<?php

namespace App\Http\Controllers;


use App\Models\Flight\FlightInfo;
use App\Models\Rbac\GuardUser;
use Barryvdh\Snappy\Facades\SnappyPdf as PDF;
use Illuminate\Http\Request;


/**
 * 用于测试的控制器
 * Class DemoController
 * @package App\Http\Controllers
 */
class DemoController extends Controller {

    public function demo() {

    }

    public function uEditor(Request $request) {
        return view('demo.uEditor');
    }

    public function dropDown(Request $request) {
        return view('demo.dropDown');

    }


    public function tableSelect(Request $request) {
        if($request->ajax()){
            $records = GuardUser::where('name','like','%'.$request->input('name').'%')
                ->get(['name','id'])->toArray();
            return responseSuccess($records,count($records));
        }

        $titles = (new GuardUser())->getTableTitleSettings();
        //$records = AdminUser::take(10)->get(['name','id as value']);
        return view('demo.tableSelect',compact('titles'));
    }

    public function xmSelect(Request $request) {

        if($request->has('tree')){
            return view('demo.xmSelect.tree');
        }

        if($request->ajax()){
            $records = GuardUser::where('name','like','%'.$request->input('name').'%') ->get(['name','id as value']);
            return json_encode(['data'=>$records]);
        }

        $records = GuardUser::take(10)->get(['name','id as value']);
        return view('demo.xmSelect.base',compact('records'));
    }


    public function eleTree(Request $request) {
        $permission = new Depart();
        $records = $permission->where('parent_id',0)->with('treeList')->get()->toArray();
        $records = json_encode($records,JSON_UNESCAPED_UNICODE);
        return view('demo.eleTree',compact('records'));
    }

}
